package com.qf.springboot.controller;

import com.qf.springboot.pojo.User;
import com.qf.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class UserController {

    private UserService userService;

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/user/{id}")
    public User findUserById(@PathVariable Long id){
        User user = userService.findUserById(id);
        return user;
    }

    @PostMapping("/user")
    public User addUser(@RequestBody User user){
        userService.addUser(user);
        return user;

    }

    @PutMapping("/user")
    public User update(@RequestBody User user){
        userService.updateUser(user);
        return user;
    }

    //@DeleteMapping("/users")
    //public User deleteUser(@RequestBody Long id){
      //  int user = userService.deleteUserById(id);
      //  return user

    //}
}
